// components/customTabBar/index.js
Component({

    /**
     * 组件的属性列表
     */
    properties: {

    },

    /**
     * 组件的初始数据
     */
    data: {
        selected: 0,
        list: [{
            pagePath: "/pages/index/index",
            text: "首页",
            iconPath: "/images/home.png",
            selectedIconPath: "/images/home-active.png"
        }, {
            pagePath: "/pages/cart/cart",
            text: "点单",
            iconPath: "/images/order.png",
            selectedIconPath: "/images/order-active.png"
        }, {
            pagePath: "",
            text: "扫码",
            isSpecial: true
        }, {
            pagePath: "/pages/orderList/orderList",
            text: "订单",
            iconPath: "/images/order.png",
            selectedIconPath: "/images/order-active.png"
        }, {
            pagePath: "/pages/my/my",
            text: "我的",
            iconPath: "/images/user.png",
            selectedIconPath: "/images/user-active.png"
        }]
    },

    /**
     * 组件的方法列表
     */
    methods: {
        switchTab(e) {
            const index = e.currentTarget.dataset.index
            const path = e.currentTarget.dataset.path

            if (index === 2) { // 中间按钮点击事件
                this.triggerEvent('showQRCode')
                return
            }

            wx.switchTab({ url: path })
            this.setData({ selected: index })
        }
    }
})